package com.qf5.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf5.domain.Student;
import com.qf5.mapper.StudentMapper;
import com.qf5.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> findAll() {
        return studentMapper.findAll();
    }

    @Override
    public Student findById(Integer id) {
        return studentMapper.findById(id);
    }

    @Override
    public PageInfo<Student> findPage(int pageNum, int pageSize) {
        //设置分页参数
        PageHelper.startPage(pageNum,pageSize);

        //执行操作
        List<Student> students = studentMapper.findAll();

        return new PageInfo<>(students);
    }

    @Override
    public int insert(Student stu) {
        return studentMapper.insert(stu);
    }

    @Override
    public int delete(Integer id) {
        return studentMapper.delete(id);
    }

    @Override
    public int update(Student stu) {
        return studentMapper.update(stu);
    }

    @Override
    public Student findByNameAndAge(String name, Integer age) {
        return studentMapper.findByNameAndAge(name,age);
    }
}
